package mlz.b_buffered;

import org.junit.Test;

import java.io.*;

/*
    缓冲字节输入流 和 缓冲字节输出流  -> 优化文件复制的效率
 */
public class BufferedDemo01 {
    @Test
    public void test() throws IOException {
        //1.创建输入流对象
        BufferedInputStream bis =
                new BufferedInputStream(
                        new FileInputStream("a.png"));
        //2.创建输出流对象
        BufferedOutputStream bos =
                new BufferedOutputStream(
                        new FileOutputStream("a_copy.png"));

        //3.做文件的复制
        byte[] bs = new byte[1024];
        int len;
        //long time1 = System.currentTimeMillis();
        while((len = bis.read(bs)) != -1){
            //写出数据
            bos.write(bs,0,len);
        }
        //long time2 = System.currentTimeMillis();
        //System.out.println(time2 - time1);
        System.out.println("复制完成");

    }
}









